package com.team11.server.controller.admin;
import com.team11.server.pojo.CInformation;
import com.team11.server.pojo.C_T_S_information;
import com.team11.server.pojo.StuInformation;
import com.team11.server.service.admin.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(tags = "管理员接口")
public class Admin_SelAll_Class_Controller {
    @Autowired
    private Admin_Sel_All_Class_Service admin_sel_all_class_service;
    @Autowired
    private Admin_Term_SelC_Service admin_term_selC_service;
    @Autowired
    private Admin_Term_SelS_Service admin_term_selS_service;
    @Autowired
    private Admin_Insert_C_Service admin_insert_c_service;
    @Autowired
    private Admin_Update_C_Service admin_update_c_service;
    @Autowired
    private Admin_Update_S_Service admin_update_s_service;
    @Autowired
    private Admin_Insert_S_Service admin_insert_s_service;

    @ApiOperation("查询班级列表(进入学生管理界面)")
    @GetMapping("/SelAllClass")
    public List<CInformation> SelAllClass(){
        return admin_sel_all_class_service.SelAllClass();
    }
    @ApiOperation("条件查询班级信息")
    @PostMapping("/TermSelC")
    public List<CInformation> Term_SelC(C_T_S_information c_t_s_information){
        return admin_term_selC_service.Term_SelC(c_t_s_information);
    }
    @ApiOperation("条件查询学生信息")
    @PostMapping("/TermSelS")
    public List<CInformation> term_selS(StuInformation stuInformation){
        return admin_term_selS_service.Term_SelS(stuInformation);
    }
    @ApiOperation("新增班级")
    @PostMapping("/Insert_C")
    public String Insert_C(C_T_S_information c_t_s_information){
        String s=admin_insert_c_service.Have_C(c_t_s_information);

        if (s.equals("1")){
            return admin_insert_c_service.Insert_C(c_t_s_information);
        }
        else
            return s;
    }

    @ApiOperation("编辑班级(需要提供班级id)")
    @PostMapping("/Update_C")
    public String Update_C(String cDepartment,String cMajor,String cGrade,
                           String cClass,String tName,String cState,Integer cId){
        HashMap<String,Object> map=new HashMap<>();
        map.put("cDepartment",cDepartment);
        map.put("cMajor",cMajor);
        map.put("cGrade",cGrade);
        map.put("cClass",cClass);
        map.put("tName",tName);
        map.put("cState",cState);
        map.put("cId",cId);
        String s=admin_update_c_service.Sel_Have_TinC(map);
        if (s.equals("1")){
            String o=admin_update_c_service.Sel_haveC(map);
            if (o.equals("1")){
                return admin_update_c_service.Update_C(map);
            }
            else return o;
        }
        else return s;
    }


    @ApiOperation("进入学生编辑界面获取学生信息(提供学生id)")
    @PostMapping("/Sel_S_toUpdate")
    public CInformation Sel_S_toUpdate(Integer sid){
        return admin_update_s_service.Sel_S_toUpdate(sid);
    }
    @ApiOperation("编辑学生")
    @PostMapping("/Update_S")
    public String Update_S(StuInformation stuInformation){
        String s=admin_update_s_service.Sel_have_S(stuInformation);
        if (s.equals("1")){
            return admin_update_s_service.Update_S(stuInformation);
        }
        else return s;
    }

    @ApiOperation("新增学生")
    @PostMapping("/Insert_S")
    public String Insert_S(StuInformation stuInformation){
        String s=admin_insert_s_service.Sel_have_T(stuInformation);
        if (s.equals("1")){
            return admin_insert_s_service.Insert_S(stuInformation);
        }
        else return s;
    }


}
